import request from '@/utils/request'

// 获取所有部门
export function getAllDepartments() {
    return request({
        url: '/departments',
        method: 'get'
    })
}

// 搜索部门
export function searchDepartments(params) {
    return request({
        url: '/departments/search',
        method: 'get',
        params
    })
}

// 根据ID获取部门
export function getDepartmentById(id) {
    return request({
        url: `/departments/${id}`,
        method: 'get'
    })
}

// 根据部门ID获取部门及其下所有用户
export function getDepartmentWithUsersById(id) {
    return request({
        url: `/departments/${id}/with-users`,
        method: 'get'
    })
}

// 获取部门下的所有用户
export function getUsersByDepartmentId(id) {
    return request({
        url: `/departments/${id}/users`,
        method: 'get'
    })
}

// 添加部门
export function addDepartment(data) {
    return request({
        url: '/departments',
        method: 'post',
        data
    })
}

// 更新部门
export function updateDepartment(id, data) {
    return request({
        url: `/departments/${id}`,
        method: 'put',
        data
    })
}

// 删除部门
export function deleteDepartment(id) {
    return request({
        url: `/departments/${id}`,
        method: 'delete'
    })
}

// 批量删除部门
export function batchDeleteDepartments(ids) {
    return request({
        url: '/departments/batch',
        method: 'delete',
        data: ids
    })
}

// 导出部门Excel
export function exportDepartments() {
    return request({
        url: '/departments/export',
        method: 'get',
        responseType: 'blob'
    })
} 